import java.util.ArrayList;
import java.util.List;
import java.util.Observer;

/**
 * @Classname Subject
 * @Description TODO
 * @Date 2023/9/1 11:10
 * @Created by wpc
 */
public class Subject {
    private List<Observers> observerList = new ArrayList<Observers>();
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void attach(Observers observers){
        this.observerList.add(observers);
    }

    public void notifyAllObservers(){
        for(Observers observers : observerList){
            observers.update();
        }
    }
}
